#pragma once

#include "workspace/IController.h"

interface IVIew;

class Controller : public IController
{
	struct DocumentControl 
	{
		DocumentControl(){document = NULL; view = NULL;}
		IDocument* document;
		IView* view;
		sys::ObjectPtr commandProcessor;
	};
	typedef std::map<uint32,sys::ObjectPtr> CommandDictionary;
	typedef std::vector<DocumentControl*> DocumentControls;

public:
	BEGIN_DEFINE_CLASS(CLSID_Controller)
		DEFINE_INTERFACE_ENTRY(IController)
	END_DEFINE_CLASS()

	Controller();
	virtual ~Controller();

	virtual void ActivateControl(IView* view,IDocument* document);
	virtual void CloseControl(IView* view,IDocument* document);
	virtual bool ExecuteCommand(uint32 commandid,ExecuteArgument* arg=NULL);
	virtual void AddCommand(uint32 commandid,vclsid clsidCommand);

protected:
	DocumentControl* AddDocumentControl(IDocument* document,IView* view);
	DocumentControls::iterator FindDocumentControl(IDocument* document,IView* view);

private:
	CommandDictionary m_commands;

	DocumentControl* m_activeDocumentControl;
	DocumentControls m_documentControls;
};
AUTO_REGISTER_CLASSMAP_ENTRY_singleton(Controller)